/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * spotInfo.java
 *
 * Created on 25-Oct-2010, 11:30:19 AM
 */
package balony;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.net.URI;
import java.text.NumberFormat;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Barry Young
 */
public class spotInfo extends javax.swing.JFrame {

    public Balony balony;
    public dataTable sourceDataTable;
    private Object tableData[][];
    public int currRow;
    public JTable sourceDT;

    /** Creates new form spotInfo */
    public spotInfo() {
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane() {

            public String getToolTipText(MouseEvent evt) {

                Point p = evt.getPoint();
                int i = viewToModel(p);
                try {
                    String t = jEditorPane1.getDocument().getText(0,
                        jEditorPane1.getDocument().getLength());
                    int start = i;
                    String c = " ,;:/\"().?[]{}";
                    while(start > 0 && !c.contains(t.substring(start, start+1))) {
                        start--;
                    }

                    int end = i;
                    while(end < t.length() && !c.contains(t.substring(end, end+1))) {
                        end++;
                    }

                    //            System.out.println("|"+t.substring(start+1,end)+"|");
                    String hover = t.substring(start+1, end).trim();
                    String desc=null;

                    if(end>start) {
                        //                System.out.println(hover);
                        for(String orf : balony.allSGDInfo.keySet()) {
                            if(orf.toLowerCase().equals(hover.toLowerCase())) {
                                desc= (balony.allSGDInfo.get(orf).gene.isEmpty() ?
                                    orf : balony.allSGDInfo.get(orf).gene) +": "+
                                balony.allSGDInfo.get(orf).desc;
                            }
                        }
                    }

                    if(desc!=null) {
                        return desc;
                    }

                    start =i;
                    c = " ,;:/\"().?[]{}-";
                    while(start > 0 && !c.contains(t.substring(start, start+1))) {
                        start--;
                    }

                    end = i;
                    while(end < t.length() && !c.contains(t.substring(end, end+1))) {
                        end++;
                    }

                    //            System.out.println("|"+t.substring(start+1,end)+"|");
                    hover = t.substring(start+1, end).trim();

                    if(hover.endsWith("p")) {
                        hover=hover.substring(0, hover.length()-1);
                    }

                    for(String orf : balony.allSGDInfo.keySet()) {
                        String gene = balony.allSGDInfo.get(orf).gene;
                        if(gene.toLowerCase().equals(hover.toLowerCase())) {
                            desc= (balony.allSGDInfo.get(orf).gene.isEmpty() ?
                                orf : balony.allSGDInfo.get(orf).gene) +": "+
                            balony.allSGDInfo.get(orf).desc;
                        }
                    }

                    if(desc!=null) {
                        return desc;
                    }

                } catch (Exception ex) {
                }
                return null;
            }
        }
        ;
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel() {
            @Override public void paintComponent(Graphics g) {
                super.paintComponent(g);    // paints background
                updatePanel(g);

                // do your drawing here
            }

        }
        ;
        jPanel2 = new javax.swing.JPanel() {
            @Override public void paintComponent(Graphics g) {
                super.paintComponent(g);    // paints background
                updatePanel2(g);

                // do your drawing here
            }

        }
        ;
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable() {

            public TableCellRenderer getCellRenderer(int row, int column) {

                TableCellRenderer t=new myRenderer(row,column);
                return t;
            }

        };
        jPanel5 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        positionJLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        orfJLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        geneJLabel = new javax.swing.JLabel();
        copiesJLabel = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        rankJLabel = new javax.swing.JLabel();

        jTextField1.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jTextField1.setText("Test text goes in here. aaaaaaaaaaaaa a aaaaaaaaaaaa aaaaaaaaaa aaaaaaaaa");
        jTextField1.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jScrollPane2.setBorder(null);

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));
        jScrollPane2.setViewportView(jTextArea1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                formFocusGained(evt);
            }
        });

        jScrollPane3.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));

        jEditorPane1.setContentType("text/html");
        jEditorPane1.setEditable(false);
        jEditorPane1.setToolTipText("");
        jEditorPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jEditorPane1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jEditorPane1MouseEntered(evt);
            }
        });
        jEditorPane1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jEditorPane1MouseMoved(evt);
            }
        });
        jScrollPane3.setViewportView(jEditorPane1);

        jButton3.setText("Prev");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Next");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Top");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setForeground(new java.awt.Color(255, 204, 51));
        jPanel1.setToolTipText("Areas of selected set");
        jPanel1.setPreferredSize(new java.awt.Dimension(100, 50));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 49, Short.MAX_VALUE)
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setForeground(new java.awt.Color(255, 204, 51));
        jPanel2.setToolTipText("Areas of all sets");
        jPanel2.setPreferredSize(new java.awt.Dimension(100, 50));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 49, Short.MAX_VALUE)
        );

        jLabel7.setText("Ctrl");

        jLabel8.setText("Exp");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel8))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(10, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Set #", "Ctrl", "Exp", "Ratio", "Diff"
            }
        ));
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButton2.setText("Jump to:");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField2KeyReleased(evt);
            }
        });

        positionJLabel.setText("(0,0,0)");

        jLabel2.setText("Gene:");

        orfJLabel.setText("Orf:");

        jLabel1.setText("Orf:");

        jButton1.setText("Find dupe");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Position:");

        jLabel9.setText("Copies in array:");

        geneJLabel.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        geneJLabel.setForeground(new java.awt.Color(0, 0, 255));
        geneJLabel.setText("Gene:");
        geneJLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        geneJLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                geneJLabelMouseClicked(evt);
            }
        });

        copiesJLabel.setText("1");

        jLabel16.setText("Rank:");

        rankJLabel.setText(" ");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel16)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(geneJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                        .addComponent(orfJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(positionJLabel))
                    .addComponent(rankJLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(copiesJLabel))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(85, 85, 85))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(orfJLabel)
                    .addComponent(jLabel9)
                    .addComponent(copiesJLabel)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(geneJLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(positionJLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(rankJLabel)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 383, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public class myRenderer extends DefaultTableCellRenderer {

        int r, c;

        public myRenderer(int row, int col) {
            super();
            r = row;
            c = col;
            setOpaque(true);
        }

        public void setAl(int al) {
            setHorizontalAlignment(al);
        }

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {

            try {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

                setHorizontalAlignment(RIGHT);
                if (row == 0) {
                    setFont(getFont().deriveFont(Font.BOLD));
                }

                if (isSelected) {
                    setForeground(Color.white);
                }

                try {
                    Double ctrl = (Double) jTable1.getValueAt(row, 1);
                    Double exp = (Double) jTable1.getValueAt(row, 2);
                    if (sourceDataTable.keepData(ctrl, exp)) {
                        setForeground(Color.black);

                        if (isSelected) {
                            setForeground(Color.white);
                        }

                        if (column == 3) {
                            if (row == 0) {
                                Hit h = (Hit) sourceDT.getModel().getValueAt(currRow, sourceDataTable.COL_HIT);
                                if (h.i == 1) {
                                    setForeground(Color.green);
                                }

                                if (h.i == 2) {
                                    setForeground(Color.red);
                                }
                            } else {

                                if (exp / ctrl < sourceDataTable.getLowCutOff()) {
                                    setForeground(Color.green);
                                }

                                if (exp / ctrl > sourceDataTable.getHighCutOff()) {
                                    setForeground(Color.red);
                                }
                            }
                        }

                    } else {
                        setForeground(Color.lightGray);
                    }
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage());
                }



            } catch (Exception e) {
                System.out.println(e.getLocalizedMessage());
            }

            return this;
        }

        @Override
        @SuppressWarnings("unchecked")
        public void setValue(Object value) {

            if (value == null) {
                return;
            }

            if (c == 0) {
                setText(value.toString());
            }

            if (value instanceof Double) {
                NumberFormat nf = NumberFormat.getNumberInstance();
                nf.setMaximumFractionDigits(4);
                setText(nf.format(value));
            } else {
                setText(value.toString());
            }

        }
    }

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        updatePanel(jPanel1.getGraphics());
    }//GEN-LAST:event_jTable1MouseClicked

    private void geneJLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_geneJLabelMouseClicked
        try {
            Desktop d = Desktop.getDesktop();
            d.browse(new URI("http://www.yeastgenome.org/cgi-bin/locus.fpl?locus="
                    + orfJLabel.getText()));
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }
    }//GEN-LAST:event_geneJLabelMouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        sourceDT.setRowSelectionInterval(0, 0);
        sourceDataTable.setupSpotInfo(this);
        sourceDT.scrollRectToVisible(sourceDT.getCellRect(
                0, 0, true));
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        int nextRow = sourceDT.convertRowIndexToView(currRow) + 1;
        try {
            sourceDT.setRowSelectionInterval(nextRow, nextRow);
            sourceDataTable.setupSpotInfo(this);
            sourceDT.scrollRectToVisible(sourceDT.getCellRect(
                    nextRow, 0, true));
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        int prevRow = sourceDT.convertRowIndexToView(currRow) - 1;
        try {
            sourceDT.setRowSelectionInterval(prevRow, prevRow);
            sourceDataTable.setupSpotInfo(this);
            sourceDT.scrollRectToVisible(sourceDT.getCellRect(
                    prevRow, 0, true));
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        String s = jTextField2.getText().toLowerCase().trim();
        doFind(s);
    }

    public void doFind(String s) {

        int row = sourceDT.convertRowIndexToView(currRow);

        boolean found = false;
        int i = row + 1;

        while (!found && i < sourceDT.getRowCount()) {
            String orf = "";
            String gene = "";
            try {
                orf = sourceDT.getValueAt(i, sourceDataTable.COL_ORF).toString().toLowerCase();
            } catch (Exception e) {
                System.out.println(e.getLocalizedMessage());
            }

            try {
                gene = sourceDT.getValueAt(i, sourceDataTable.COL_GENE).toString().toLowerCase();
            } catch (Exception e) {
                System.out.println(e.getLocalizedMessage());
            }

            if (orf.equals(s) || gene.equals(s)) {
                found = true;
            }

            i++;
        }

        if (found == true) {
            i--;
            sourceDT.setRowSelectionInterval(i, i);
            sourceDataTable.setupSpotInfo(this);
            sourceDT.scrollRectToVisible(sourceDT.getCellRect(i, 0, true));
            return;
        } else {

            i = 0;
            while (!found && i < row) {
                String orf = "";
                String gene = "";
                try {
                    orf = sourceDT.getValueAt(i, sourceDataTable.COL_ORF).toString().toLowerCase();
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage());
                }

                try {
                    gene = sourceDT.getValueAt(i, sourceDataTable.COL_GENE).toString().toLowerCase();
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage());
                }

                if (orf.equals(s) || gene.equals(s)) {
                    found = true;
                }

                i++;
            }

            if (found == true) {
                i--;
                sourceDT.setRowSelectionInterval(i, i);
                sourceDataTable.setupSpotInfo(this);
                sourceDT.scrollRectToVisible(sourceDT.getCellRect(i, 0, true));
                return;
            }
        }

        i = row + 1;
        while (!found && i < sourceDT.getRowCount()) {
            String orf = "";
            String gene = "";
            try {
                orf = sourceDT.getValueAt(i, sourceDataTable.COL_ORF).toString().toLowerCase();
            } catch (Exception e) {
                System.out.println(e.getLocalizedMessage());
            }

            try {
                gene = sourceDT.getValueAt(i, sourceDataTable.COL_GENE).toString().toLowerCase();
            } catch (Exception e) {
                System.out.println(e.getLocalizedMessage());
            }

            if (orf.contains(s) || gene.contains(s)) {
                found = true;
            }

            i++;
        }

        if (found == true) {
            i--;
            sourceDT.setRowSelectionInterval(i, i);
            sourceDataTable.setupSpotInfo(this);
            sourceDT.scrollRectToVisible(sourceDT.getCellRect(i, 0, true));
        } else {

            i = 0;
            while (!found && i < row) {
                String orf = "";
                String gene = "";
                try {
                    orf = sourceDT.getValueAt(i, sourceDataTable.COL_ORF).toString().toLowerCase();
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage());
                }

                try {
                    gene = sourceDT.getValueAt(i, sourceDataTable.COL_GENE).toString().toLowerCase();
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage());
                }

                if (orf.contains(s) || gene.contains(s)) {
                    found = true;
                }

                i++;
            }

            if (found == true) {
                i--;
                sourceDT.setRowSelectionInterval(i, i);
                sourceDataTable.setupSpotInfo(this);
                sourceDT.scrollRectToVisible(sourceDT.getCellRect(i, 0, true));
            }
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            String s = jTextField2.getText().toLowerCase();
            doFind(s);
        }
    }//GEN-LAST:event_jTextField2KeyReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String s = orfJLabel.getText().toLowerCase();
        doFind(s);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
    }//GEN-LAST:event_formFocusGained

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
        int i = sourceDT.convertRowIndexToView(currRow);
        if(i>0 && i<sourceDT.getRowCount()) {
        sourceDT.setRowSelectionInterval(i, i);
        sourceDT.scrollRectToVisible(sourceDT.getCellRect(i, 0, true));
        }
    }//GEN-LAST:event_formWindowGainedFocus

    private void jEditorPane1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jEditorPane1MouseEntered
    }//GEN-LAST:event_jEditorPane1MouseEntered

    private void jEditorPane1MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jEditorPane1MouseMoved
//        Point p = evt.getPoint();
//        int i = jEditorPane1.viewToModel(p);
//        String t = null;
//        try {
//            t = jEditorPane1.getDocument().getText(0, jEditorPane1.getDocument().getLength());
//
//            int start = i;
//            String c = " ,;:/\"().?[]{}";
//            while (start > 0 && !c.contains(t.substring(start, start + 1))) {
//                start--;
//            }
//
//            int end = i;
//            while (end < t.length() && !c.contains(t.substring(end, end + 1))) {
//                end++;
//            }
//            String hover = t.substring(start + 1, end).trim();
//
//            if ((Boolean) jEditorPane1.getDocument().getProperty(hover)) {
//                setCursor(new Cursor(Cursor.HAND_CURSOR));
//            } else {
//                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
//            }
//        } catch (Exception ex) {
//            System.out.println(ex.getLocalizedMessage());
//        }
    }//GEN-LAST:event_jEditorPane1MouseMoved

    private void jEditorPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jEditorPane1MouseClicked

//        if(evt.getClickCount()==2) {

        Point p = evt.getPoint();
        int i = jEditorPane1.viewToModel(p);
        try {
            String t = jEditorPane1.getDocument().getText(0,
                    jEditorPane1.getDocument().getLength());
            int start = i;
            String c = " ,;:/\"().?[]{}";
            while (start > 0 && !c.contains(t.substring(start, start + 1))) {
                start--;
            }

            int end = i;
            while (end < t.length() && !c.contains(t.substring(end, end + 1))) {
                end++;
            }

            String hover = t.substring(start + 1, end).trim();

            if (end > start) {
                System.out.println(hover);
                for (String orf : balony.allSGDInfo.keySet()) {
                    if (orf.toLowerCase().equals(hover.toLowerCase())) {
                        doFind(hover.toLowerCase());
                        return;
                    }
                }
            }


            start = i;
            c = " ,;:/\"().?[]{}-";
            while (start > 0 && !c.contains(t.substring(start, start + 1))) {
                start--;
            }

            end = i;
            while (end < t.length() && !c.contains(t.substring(end, end + 1))) {
                end++;
            }

            System.out.println("|" + t.substring(start + 1, end) + "|");
            hover = t.substring(start + 1, end).trim();

            if (hover.endsWith("p")) {
                hover = hover.substring(0, hover.length() - 1);
            }

            for (String orf : balony.allSGDInfo.keySet()) {
                String gene = balony.allSGDInfo.get(orf).gene;
                if (gene.toLowerCase().equals(hover.toLowerCase())) {
                    doFind(balony.allSGDInfo.get(orf).gene.toLowerCase());
                    return;
                }
            }


        } catch (Exception ex) {
            System.out.println(ex.getLocalizedMessage());
        }
    }//GEN-LAST:event_jEditorPane1MouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new spotInfo().setVisible(true);
//            }
//        });
//    }
    public void updatePanel(Graphics g) {
        Graphics2D ga = (Graphics2D) g;
        if (ga == null) {
            return;
        }

        int i = jTable1.getSelectedRow();

        if (tableData[i][1] != null && tableData[i][2] != null) {

            double r1 = Math.sqrt((Double) tableData[i][1]) * 30;
            double r2 = Math.sqrt((Double) tableData[i][2]) * 30;

            ga.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            ga.setBackground(Color.black);
            ga.clearRect(0, 0, 100, 100);


            float[] frac = {0f, 1.0f};
            Color[] colors = {new Color(255, 175, 132), Color.yellow};
            if (r1 > 0) {
                Point2D center = new Point2D.Float((float) (30 - r1 / 4), (float) (25 - r1 / 4));

                RadialGradientPaint rgp = new RadialGradientPaint(center, (float) r1, frac, colors);

                ga.setPaint(rgp);
                ga.fillOval((int) (30 - r1 / 2), (int) (25 - r1 / 2), (int) r1, (int) r1);
            }


            if (r2 > 0) {
                Point2D center = new Point2D.Float((float) (70 - r2 / 4), (float) (25 - r2 / 4));
                RadialGradientPaint rgp = new RadialGradientPaint(center, (float) r2, frac, colors);
                ga.setPaint(rgp);

                ga.fillOval((int) (70 - r2 / 2), (int) (25 - r2 / 2), (int) r2, (int) r2);
            }
        }
    }

    public void updatePanel2(Graphics g) {
        Graphics2D ga = (Graphics2D) g;

        if (ga == null) {
            return;
        }
        ga.setBackground(Color.white);
        ga.clearRect(0, 0, 100, 100);

        for (int i = 0; i < tableData.length; i++) {
            if (tableData[i][1] != null && tableData[i][2] != null) {
                double r1 = Math.sqrt((Double) tableData[i][1]) * 30;
                double r2 = Math.sqrt((Double) tableData[i][2]) * 30;

                ga.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                ga.setColor(Color.red);
                ga.drawOval((int) (30 - r1 / 2), (int) (25 - r1 / 2), (int) r1, (int) r1);
                ga.drawOval((int) (70 - r2 / 2), (int) (25 - r2 / 2), (int) r2, (int) r2);
            }
        }
    }

    public void setRank(int i) {
        rankJLabel.setText("" + i);
    }

    public void setCopies(int i) {
        copiesJLabel.setText("" + i);
    }

    public void setOrf(String s) {
        orfJLabel.setText(s);
    }

    public void setGene(String s) {
        geneJLabel.setText("<html><u>" + s + "</u></html>");
    }

    public void setPosition(int i, int j, int k) {
        positionJLabel.setText("(" + i + "," + j + "," + k + ")");
    }

    public void setupTable(Double[] ctrl, Double[] exp) {

        int j = 0;
        for (int i = 1; i < ctrl.length; i++) {
            if (ctrl[i] != null && exp[i] != null) {
                j++;
            }
        }

        tableData = new Object[j + 1][5];

        j = 0;

        Double[] ratio, diff;

        ratio = new Double[ctrl.length];
        diff = new Double[ctrl.length];

        Double d;

        tableData[0][0] = "Mean";

        try {
            d = (Double) sourceDT.getModel().getValueAt(currRow, sourceDataTable.COL_RATIO);
            tableData[j][3] = d;
        } catch (Exception e) {
            tableData[j][3] = "-";

        }

        try {
            d = (Double) sourceDT.getModel().getValueAt(currRow, sourceDataTable.COL_CTRL);
            tableData[j][1] = d;

        } catch (Exception e) {
            tableData[j][1] = "-";
        }

        try {
            d = (Double) sourceDT.getModel().getValueAt(currRow, sourceDataTable.COL_EXP);
            tableData[j][2] = d;
        } catch (Exception e) {
            tableData[j][2] = "-";
        }

        try {
            d = (Double) sourceDT.getModel().getValueAt(currRow, sourceDataTable.COL_DIFF);
            tableData[j][4] = d;
        } catch (Exception e) {
            tableData[j][4] = "-";
        }

        for (int i = 1; i < ctrl.length; i++) {
            if (ctrl[i] != null && exp[i] != null) {
                j++;
                tableData[j][0] = i;
                tableData[j][1] = sourceDataTable.getAdjustedSpotSize(ctrl[i]);
                tableData[j][2] = sourceDataTable.getAdjustedSpotSize(exp[i]);

                if (sourceDataTable.keepData(ctrl[i], exp[i])) {
                    ratio[i] = (Double) tableData[j][2] / (Double) tableData[j][1];
                    tableData[j][3] = ratio[i];
                } else {
                    tableData[j][3] = "-";
                }

                diff[i] = (Double) tableData[j][2] - (Double) tableData[j][1];
                tableData[j][4] = diff[i];

            }
        }

        jTable1.setModel(new MyTableModel());
    }

    class MyTableModel extends AbstractTableModel {

        private String[] columnNames = {"Set #", "Ctrl", "Exp", "Ratio", "Diff"};

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public int getRowCount() {
            return getTableData().length;
        }

        @Override
        public String getColumnName(int col) {
            return columnNames[col];
        }

        @Override
        public Object getValueAt(int row, int col) {
            return getTableData()[row][col];
        }

        @Override
        public Class<?> getColumnClass(int c) {
            if (c == 9 || c == 7 || c == 5) {
                return Object.class;
            }

            if (getValueAt(0, c) != null) {
                return getValueAt(0, c).getClass();
            } else {
                return String.class;
            }
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            return false;
        }
    }

    public Object[][] getTableData() {
        return tableData;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel copiesJLabel;
    private javax.swing.JLabel geneJLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    public javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    public javax.swing.JTable jTable1;
    public javax.swing.JTextArea jTextArea1;
    public javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JLabel orfJLabel;
    public javax.swing.JLabel positionJLabel;
    public javax.swing.JLabel rankJLabel;
    // End of variables declaration//GEN-END:variables
}
